home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / OldSrc / CH10 / SRC / OBJPICT5.CLS < prev    next >
Encoding:
Text File  |  1996-05-04  |  3.8 KB  |  146 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "ObjPicture"
  6. Attribute VB_Creatable = False
  7. Attribute VB_Exposed = False
  8. Option Explicit
  9.  
  10. Public objects As New Collection
  11.  
  12. Const TYPE_STRING = "3D APF PICTURE"
  13.  
  14.  
  15. ' ************************************************
  16. ' Find an object that contains this point.
  17. ' ************************************************
  18. Function NearestObject(x As Single, y As Single) As Object
  19. Dim obj As Object
  20.        
  21.     ' Find the object.
  22.     For Each obj In objects
  23.         If obj.Contains(x, y) Then
  24.             Set NearestObject = obj
  25.             Exit Function
  26.         End If
  27.     Next obj
  28.     Set NearestObject = Nothing
  29. End Function
  30.  
  31.  
  32. Function ObjectType() As String
  33.     ObjectType = TYPE_STRING
  34. End Function
  35. ' ***********************************************
  36. ' Fix the data coordinates at their transformed
  37. ' values.
  38. ' ***********************************************
  39. Public Sub FixPoints()
  40. Dim obj As Object
  41.  
  42.     For Each obj In objects
  43.         obj.FixPoints
  44.     Next obj
  45. End Sub
  46.  
  47. ' ************************************************
  48. ' Read the picture from a file using Input.
  49. ' Assume TYPE_STRING has already been read.
  50. ' ************************************************
  51. Sub FileInput(filenum As Integer)
  52. Dim num As Integer
  53. Dim i As Integer
  54. Dim obj As Object
  55. Dim obj_type As String
  56.  
  57.     ' Read the number of objects in the file.
  58.     Input #filenum, num
  59.     
  60.     ' Repeatedly read objects from the file.
  61.     For i = 1 To num
  62.         Input #filenum, obj_type
  63.         Select Case obj_type
  64.             Case TYPE_STRING
  65.                 Set obj = New ObjPicture
  66.             Case "POLYLINE"
  67.                 Set obj = New ObjPolyline
  68.             Case "GRID"
  69.                 Set obj = New ObjGrid3D
  70.             Case "SPARSE_GRID"
  71.                 Set obj = New ObjSparseGrid
  72.             Case "BEZIER"
  73.                 Set obj = New ObjBezier
  74.             Case Else
  75.                 Beep
  76.                 MsgBox "Unknown object type """ & obj_type & """.", , vbExclamation
  77.                 Exit Sub
  78.         End Select
  79.         obj.FileInput filenum
  80.         objects.Add obj
  81.     Next i
  82. End Sub
  83.  
  84. ' ************************************************
  85. ' Draw the picture on a Form, Printer, or
  86. ' PictureBox.
  87. ' ************************************************
  88. Sub Draw(canvas As Object, Optional r As Variant)
  89. Dim obj As Object
  90.  
  91.     For Each obj In objects
  92.         obj.Draw canvas, r
  93.     Next obj
  94. End Sub
  95.  
  96. ' ************************************************
  97. ' Write the picture to a file using Write.
  98. ' Begin with TYPE_STRING to identify this object.
  99. ' ************************************************
  100. Sub FileWrite(filenum As Integer)
  101. Dim obj As Object
  102.  
  103.     Write #filenum, TYPE_STRING
  104.     Write #filenum, objects.Count
  105.     
  106.     For Each obj In objects
  107.         obj.FileWrite filenum
  108.     Next obj
  109. End Sub
  110.  
  111. ' ************************************************
  112. ' Apply a nonlinear transformation to the objects.
  113. ' ************************************************
  114. Sub Distort(trans As Object)
  115. Dim obj As Object
  116.  
  117.     For Each obj In objects
  118.         obj.Distort trans
  119.     Next obj
  120. End Sub
  121.  
  122.  
  123. ' ************************************************
  124. ' Apply a transformation matrix which may not
  125. ' contain 0, 0, 0, 1 in the last column to the
  126. ' objects.
  127. ' ************************************************
  128. Sub ApplyFull(M() As Single)
  129. Dim obj As Object
  130.  
  131.     For Each obj In objects
  132.         obj.ApplyFull M
  133.     Next obj
  134. End Sub
  135. ' ************************************************
  136. ' Apply a transformation matrix to the objects.
  137. ' ************************************************
  138. Sub Apply(M() As Single)
  139. Dim obj As Object
  140.  
  141.     For Each obj In objects
  142.         obj.Apply M
  143.     Next obj
  144. End Sub
  145.  
  146.